package rbac.View.Main.View;

import java.util.Scanner;

public class View extends BaseView {
    public static final String MENU = """
            --------------
                RBAC系统
            --------------
             | 0 退出系统 |
             | 1 部门管理 |
             | 2 角色管理 |
             | 3 用户管理 |
            --------------
            请输入选项：""";
    public static Scanner input;
    private static View singleton;

    static {
        input = new Scanner(System.in);
    }

    private final DeptView deptview;
    private final RoleView roleview;
    private final UserView userview;

    private View() {
        deptview = DeptView.getInstance();
        roleview = RoleView.getInstance();
        userview = UserView.getInstance();
    }

    public static View getInstance() {
        if (singleton == null) {
            singleton = new View();
        }
        return singleton;
    }

    public void show() {
        String menuChoice;
        do {
            System.out.println(MENU);
            menuChoice = input.nextLine();
            switch (menuChoice) {
                case "0" -> System.out.println("成功退出系统，欢迎再次使用！");
                case "1" -> deptview.show();
                case "2" -> roleview.show();
                case "3" -> userview.show();
                default -> System.out.println("输入非法，请输入正确的菜单编号！");
            }
        } while (!"0".equals(menuChoice));
        input.close();
    }
}
